const LocalStorageUtil = {
  setLocalStorage(Item,value, expireInMinutes = 120) { // 默认过期时间为30分钟
      const expiresAt = Date.now() + (expireInMinutes * 60 * 1000); // 计算过期时间戳
      localStorage.setItem(Item, value);
      localStorage.setItem('tokenExpiresAt'+Item, expiresAt.toString());
  },
  getLocalStorage(Item) {
      const expiresAt = Number(localStorage.getItem('tokenExpiresAt'+Item));
      if (Date.now() > expiresAt) { // 当前时间大于过期时间
          this.removeLocalStorage(); // 移除过期的token
          return null;
      }
      return localStorage.getItem(Item);
  },
  removeLocalStorage(Item) {
      localStorage.removeItem(Item);
      localStorage.removeItem('tokenExpiresAt'+Item); // 同时移除过期时间
  }
};

export default LocalStorageUtil;